CMAKE_MINIMUM_REQUIRED(VERSION 3.12...3.19)

PROJECT(adder-tests)

IF(CMAKE_USER_TESTNGPP_PATH)
SET(USER_TESTNGPP_PATH ${CMAKE_USER_TESTNGPP_PATH})
ELSE(CMAKE_USER_TESTNGPP_PATH)
SET(USER_TESTNGPP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../testngpp)
ENDIF(CMAKE_USER_TESTNGPP_PATH)

INCLUDE(${USER_TESTNGPP_PATH}/testngpp.cmake)

find_package (Python3 COMPONENTS Interpreter)

IF(Python3_FOUND)
    SET(PYTHON ${Python3_EXECUTABLE})
ELSE()
    MESSAGE(FATAL_ERROR "No Python interpreter found")
ENDIF(Python3_FOUND)

MESSAGE("TESTNGPP_OS_COMPILER in CMakeLists: ")
MESSAGE(${TESTNGPP_OS_COMPILER})

IF(CMAKE_CL_64)
    ADD_DEFINITIONS(-DWIN64)
ENDIF(CMAKE_CL_64)

IF(MSVC)
    ADD_DEFINITIONS(-DMSVC_VMG_ENABLED)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vmg")
ENDIF(MSVC)

IF(UNIX OR MINGW)
ADD_DEFINITIONS(
    -g -ggdb
)
ENDIF(UNIX OR MINGW)

IF(UNIX AND NOT CYGWIN)
ADD_DEFINITIONS(
    -fPIC
)
ENDIF(UNIX AND NOT CYGWIN)

link_directories(
  ${CMAKE_CURRENT_BINARY_DIR}/../project/src
  ${USER_TESTNGPP_PATH}/binary/${TESTNGPP_OS_COMPILER}/testngpp/lib
  ${USER_TESTNGPP_PATH}/binary/${TESTNGPP_OS_COMPILER}/mockcpp/lib
)

INCLUDE_DIRECTORIES(BEFORE 
  ${PROJECT_SOURCE_DIR}/../../include
  ${USER_TESTNGPP_PATH}/include
)

SET(TEST_GENERATOR ${USER_TESTNGPP_PATH}/generator/testngppgen.py)
SET(TESTCASE_PREFIX adder-ut)

SET(UT_CASES
  TestAdder.h
)

FOREACH(CASE ${UT_CASES})
  GET_FILENAME_COMPONENT(CASE_NAME ${CASE} NAME_WE)
  SET(CASE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${CASE_NAME}.cpp)

  ADD_CUSTOM_TARGET(${CASE_NAME} DEPENDS ${CASE_SRC})

  SET(CASE_MODULE ${TESTCASE_PREFIX}-${CASE_NAME})

  ADD_LIBRARY(${CASE_MODULE} MODULE ${CASE_SRC})

  TARGET_LINK_LIBRARIES(${CASE_MODULE}
    adder
    testngpp-static
    mockcpp)

  ADD_CUSTOM_COMMAND(
    OUTPUT ${CASE_SRC}
    COMMAND ${PYTHON} ${TEST_GENERATOR} -e utf8 -o ${CASE_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/${CASE}
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CASE}
  )

  ADD_DEPENDENCIES(${CASE_MODULE} ${CASE_NAME})
ENDFOREACH()
